<?php

require_once "class/Load.class.php";
require_once "class/Sql.class.php";
require_once "class/Inputs.class.php";
require_once "class/Config.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/SessionRoster.class.php";
require_once "class/Localization.class.php";

$load = Load::GetInstance();
$sql = Sql::GetInstance();
$inputs = Inputs::GetInstance();
$config = Config::GetInstance();
$status_roster = StatusRoster::GetInstance();
$session_roster = SessionRoster::GetInstance();
$localization = Localization::GetInstance();

if ( $inputs->HasPostData('submit') )
{
	if ( $sql->Query("CREATE TABLE `cp_specializations` (  `specialization_id` mediumint(9) NOT NULL auto_increment,  `CharacterName` varchar(50) collate latin1_general_ci NOT NULL,  `Specialization` varchar(50) collate latin1_general_ci NOT NULL,  PRIMARY KEY  (`specialization_id`),  UNIQUE KEY `UNIQUE` (`CharacterName`,`Specialization`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;") != true )
	{
		$status_roster->AddError( $localization->Get('could not update roster: %s', $sql->GetLastError()) );
		$status_roster->AddNote( $localization->Get('your roster is maybe already up to date') );
	}
	else
	{
		$status_roster->AddSuccess( $localization->Get('roster successfully updated') );
		$status_roster->AddNote( $localization->Get('you can now delete the update script and go back on the %s main page', "index.php") );
	}
	
	$session_roster->SaveStatus($status_roster);
	$session_roster->Redirect('update-200.php');
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo $config->HasRosterTitle() ?  " - ".$config->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		
		<h2><?php echo $localization->Get('update'); ?></h2>
		
		<?php
		if ($session_roster->HasStatus())
		{
		?>
			
			<p>
				<?php echo $localization->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo $session_roster->GetStatus()->GetStack_InList(); ?>
			
			<p>
				<?php echo $localization->Get('you can refresh the page %s and try again', "update-200.php"); ?>
			</p>
			
		<?php
		}
		else
		{
		?>
		
		<form action="update-200.php" method="post">
		<p style="text-align: center;">
			<?php echo $localization->Get('in order to update your roster, simply click on the button below'); ?><br />
			<input type="submit" name="submit" value="<?php echo $localization->Get('update'); ?>" />
		</p>
		</form>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>